#!/usr/bin/python3

import json

from fastapi import FastAPI
from typing import Optional
from fastapi.middleware.cors import CORSMiddleware

app = FastAPI()

origins = [
    "http://localhost:3001",
]

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)


@app.get("/")
def read_root():
    return {"Hello": "World"}


@app.get("/code/{code_id}")
def read_item(code_id: str, q: Optional[str] = None):
    return {"code_id": code_id, "q": q}
